<?php

/*

  Action	$5
 
  Trash a Treasure card from your hand.
  Gain a Treasure card costing up to $3 more, put it into your hand.

 */

class Mine extends Card implements iAction, iKingdom, iBasic {

    public function __construct() {
        parent::__construct("Mine", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash a Treasure card from your hand. Gain a Treasure card costing up to $3 more, put it into your hand.");
    }
    
    public function play(Game $game, $isRealCard) {

        $treasures = array();
        $playHand = $game->getPlayHand();
        foreach ($playHand as $c) {
            if ($c instanceof iTreasure) {
                $treasures[] = $c;
            }
        }
		
        if (sizeof($treasures) > 0) {
			
			$treasures = getUniqueCards($treasures);
			if (sizeof($treasures) > 1) {
				$output = MySocket::GetUserReply($game, Input_ChooseOne, $treasures, 1, 1, null, "Choose a card to trash");
				$old_card_name = $output[0];
			}
			else {
				$old_card_name = $treasures[0];
			}
            $old_card = $game->moveCardFromPileToPile($old_card_name, PlayHand, Trash);
             ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($old_card), "trashes " . ScreenDisplay::$LMSG);
            
            //now get the price and offer option to the player
            $price = $old_card->getPrice($game);
            $optional_treasures = $game->getBoardTreasureCardsByPrice(new Price(), $price->add(3));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_treasures, 1, 1, null, "Choose a card to gain");

            $new_card_name = $output[0];
            $new_card = $game->moveCardFromPileToPile($new_card_name, BoardCards, PlayHand);
            ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($new_card), " and gains " .ScreenDisplay::$LMSG);
        }
		else {
			ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");
		}

        $game->cardActionFinished();
        return true;
    }

}

?>